template<typename Type>
class FindMinMaxCount {
    Type min;
    int min_count;
    Type max;
    int max_count;
public:
    auto init(Type const & min_, Type const & max_) {
        min = min_;
        max = max_;
        min_count = 1;
        max_count = 1;
    }
    auto fit(Type val) {
        if (val > max) {
            max = val;
            max_count = 1;
            return;
        }
        if (val == max) {
            max_count += 1;
        }
        if (val < min) {
            min = val;
            min_count = 1;
            return;
        }
        if (val == min) {
            min_count += 1;
        }
    }
    auto get_max() { return max; }
    auto get_max_count() { return max_count; }
    auto get_min() { return min; }
    auto get_min_count() { return min_count; }
};

#include <iostream>
#include <numeric>

int main() {
    FindMinMaxCount<int> solver;
    
    int cases;
    std::cin >> cases;
    
    int val;
    std::cin >> val;
    solver.init(val, val);
    --cases;
    
    while (cases > 0) {
        std::cin >> val;
        solver.fit(val);
        --cases;
    }
    std::cout << solver.get_min() << " " << solver.get_min_count() << "\n";
    std::cout << solver.get_max() << " " << solver.get_max_count() << "\n";
}
